package com.rockwell.sniffyHunter.test;

import java.util.HashMap;
import java.util.Map;

import junit.framework.Assert;

import android.annotation.SuppressLint;
import com.rockwell.sniffyhunter.model.PickTreasure;
import com.rockwell.sniffyhunter.model.Robot;
import com.rockwell.sniffyhunter.utils.DetectionIndex;
import com.rockwell.sniffyhunter.utils.IDetector;
import com.rockwell.sniffyhunter.utils.IRobotCommander;
import com.rockwell.sniffyhunter.utils.IRobotSensors;
import com.rockwell.sniffyhunter.utils.PickTreasureState;

public class Pick_PickTreasureTester extends UnitTestLooper {
	private IRobotSensors 			sensor;
	private Map<Integer, IDetector>	colorDetectors;
	private FakeTreasureDetector	treasureDetector;
	private FakeTreasureCollector 	treasureCollector;
	private IRobotCommander 		robotCommander;
	private Robot 					robot;		
	private PickTreasure 			pick_pickTreasureObj;
	
	@SuppressLint("UseSparseArrays") @SuppressWarnings("serial")
	@Override
	public void setUp() {
		sensor 				= new FakeRobotSensors();
		treasureDetector 	= new FakeTreasureDetector();
		colorDetectors 		= new HashMap<Integer, IDetector>() {
							  {
								  put(DetectionIndex.TREASURE, treasureDetector);
								  put(DetectionIndex.OBSTACLE, new FakeColorDetector()/*obstacle detector*/); 
								  put(DetectionIndex.MAZE1, new FakeColorDetector()/*maze1 detector*/);
								  put(DetectionIndex.MAZE2, new FakeColorDetector()/*maze2 detector*/);
								  put(DetectionIndex.MAZE3, new FakeColorDetector()/*maze3 detector*/);
								  put(DetectionIndex.DROPZONE, new FakeColorDetector()/*dropZone detector*/);
								  put(DetectionIndex.MAZE_EXIT, new FakeColorDetector()/*dropZone detector*/);
							  }};
		robotCommander 		= new DummyRobotCommander();
		treasureCollector 	= new FakeTreasureCollector();
		treasureCollector 	= new FakeTreasureCollector();
		robot 				= new Robot(0, 0, 
								1 /*start Zone*/,
								sensor,  
								robotCommander, 
								null/*maze*/, 
								null/*solver*/, 
								colorDetectors, 
								treasureCollector);		
		pick_pickTreasureObj = new PickTreasure(robot);
	}
	
	@Override
	public void tearDown() {

	}
	
	public void testPick_PickTreasureState() {
		Assert.assertEquals(pick_pickTreasureObj.getStateMachine(), PickTreasureState.START);
		pick_pickTreasureObj.PerformAction();
		Assert.assertEquals(pick_pickTreasureObj.getStateMachine(), PickTreasureState.LOWER_PICK_ARM);
		
		loopUntilCondition(pick_pickTreasureObj, PickTreasureState.INDEX);
		Assert.assertEquals(pick_pickTreasureObj.getStateMachine(), PickTreasureState.INDEX);
		
		loopUntilCondition(pick_pickTreasureObj, PickTreasureState.PICK_UP);
		Assert.assertEquals(pick_pickTreasureObj.getStateMachine(), PickTreasureState.PICK_UP);
		
		loopUntilCondition(pick_pickTreasureObj, PickTreasureState.MOVE_BACK);
		Assert.assertEquals(pick_pickTreasureObj.getStateMachine(), PickTreasureState.MOVE_BACK);
		
		loopUntilCondition(pick_pickTreasureObj, PickTreasureState.CHECK_PICKED);
		Assert.assertEquals(pick_pickTreasureObj.getStateMachine(), PickTreasureState.CHECK_PICKED);
		
		loopUntilCondition(pick_pickTreasureObj, PickTreasureState.LOWER_PICK_ARM);
		Assert.assertEquals(pick_pickTreasureObj.getStateMachine(), PickTreasureState.LOWER_PICK_ARM);
	}
}
